package nancal.mp.db.mongo.entity

import nbcp.base.db.IdName
import nbcp.base.enums.RecursionReturnEnum
import nbcp.base.extend.FromJson
import nbcp.base.model.BaseMarkEntity
import nbcp.base.utils.RecursionUtil

/**
 * 企业微信设置
 */
data class CorpWxSetting(
        var appId: String = "",
        var mchId: String = "",
        var key: String = "",
        var secret: String = "",
        var notify_url: String = ""
)

///**
// * 一级菜单
// */
//data class SiteMenuItem(
//        var id: String = "",
//        var name: String = "",
//        var article: IdName = IdName(),
//        var link: String = "",    //链接，文章二选一，
//        var css: String = ""
//)

/**
 * Saas菜单
 */
open class SaasMenuItem(
        var name: String = "",
        var url: String = "",
        var css: String = "",
        //暂时保留，表示用户拥有菜单对应页面的集合。
        var pages: LinkedHashMap<String, String> = linkedMapOf(),
        var subMenus: MutableList<nancal.mp.db.mongo.entity.SaasMenuItem> = mutableListOf()
) : BaseMarkEntity() {
    companion object {
        fun loadFromJson(json: String): nancal.mp.db.mongo.entity.SaasMenuItem {
            return json.FromJson<nancal.mp.db.mongo.entity.SaasMenuItem>() ?: nancal.mp.db.mongo.entity.SaasMenuItem();
        }
    }

    /**
     * 当前及子节点下所有的 url + pages 集合.
     */
    val permissions: List<String>
        get() {
            var list = mutableListOf<String>()

            RecursionUtil.execute(mutableListOf<nancal.mp.db.mongo.entity.SaasMenuItem>(this), { it.subMenus }, { wbs, index ->
                var it = wbs.last();
                list.add(it.url)
                list.addAll(it.pages.keys);
                RecursionReturnEnum.GO
            });

            return list.distinct();
        }
}

/**
 * Saas平台部门角色
 */
open class DeptDefine(
        var isManager: Boolean = false
) : IdName()


/**
 * Devops系统中项目成员的角色
 */
open class UserProjectDefine(
        var devopsRoles: MutableList<String> = mutableListOf()
) : IdName()